@extends('layouts._app')
@section('content')
    <body>
    <div class="wrap-container">
        @include('layouts._flash')
        {!! Form::open(['route' => ['system.permission.update',$permission->id],'class'=>'layui-form','style'=>'width: 90%;padding-top: 20px;','method'=>'put']) !!}
        <div class="layui-form-item">
            {!! Form::label('','上级：',['class'=>'layui-form-label']) !!}
            <div class="layui-input-block">
                <select name="parent_id" lay-verify="required">
                    <option value="0">顶级菜单</option>
                    @if($permissions)
                        @foreach($permissions as $value)
                            <option @if($value->id == $permission->parent_id) selected @endif
                            @if($permission->id == $value->id) disabled @endif
                                    value="{{$value->id}}">{{$value->name}}</option>
                            @foreach($value->children as $children)
                                @if($value->id == $children->parent_id)
                                    <option @if($children->id == $permission->parent_id) selected @endif
                                    @if($permission->id == $value->id) disabled @endif
                                            value="{{$children->id}}">
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├─{{$children->name}}</option>
                                    @foreach($children->children as $child)
                                        @if($children->id == $child->parent_id)
                                            <option disabled>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├─{{$child->name}}</option>
                                        @endif
                                    @endforeach
                                @endif
                            @endforeach
                        @endforeach
                    @endif
                </select>
            </div>

        </div>
        <div class="layui-form-item">
            {!! Form::label('','名称：',['class'=>'layui-form-label']) !!}
            <div class="layui-input-block">
                {!! Form::text('name',"{$permission->name}",['required','lay-verify'=>'required','class'=>'layui-input','placeholder'=>'请输入名称']) !!}
            </div>

        </div>
        <div class="layui-form-item">
            {!! Form::label('','路由：',['class'=>'layui-form-label']) !!}
            <div class="layui-input-block">
                {!! Form::text('label',"{$permission->label}",['required','lay-verify'=>'required','class'=>'layui-input','placeholder'=>'请输入路由']) !!}
            </div>

        </div>
        <div class="layui-form-item">
            {!! Form::label('','是否跳转：',['class'=>'layui-form-label']) !!}
            <div class="layui-input-block">
                <input type="radio" name="pid" value="1" title="是" @if($permission->pid == 1) checked @endif>
                <input type="radio" name="pid" value="2" title="否" @if($permission->pid == 2) checked @endif>
            </div>

        </div>
        <div class="layui-form-item">
            {!! Form::label('','排序：',['class'=>'layui-form-label']) !!}
            <div class="layui-input-block">
                {!! Form::text('sort_order',"{$permission->sort_order}",['required','lay-verify'=>'required','class'=>'layui-input','placeholder'=>'请输入排序']) !!}
            </div>

        </div>
        <div class="layui-form-item">
            {!! Form::label('','图标：',['class'=>'layui-form-label']) !!}
            <div class="layui-input-block">
                <input type="text" name="icon" id="icon" class="layui-input" value="{{$permission->icon}}"
                       placeholder="请输入图标" oninput="myFunction()">
                <i class="{{$permission->icon}}" id="icon_input"
                   style="font-size: 25px;float: right;margin: -32px 10px 0 0; color: #1E9FFF;"></i>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                {!! Form::submit('立即提交',['class'=>'layui-btn layui-btn-normal','lay-filter'=>'formDemo','lay-submit']) !!}
                {!! Form::reset('重置',['class'=>'layui-btn layui-btn-primary']) !!}
            </div>
        </div>
        {!! Form::close() !!}
    </div>
    <script src="{{asset('static/admin/layui/layui.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/jquery.min.js')}}" type="text/javascript" charset="utf-8"></script>
    <script>
        function myFunction() {
            var a = $('#icon').val();
            $('#icon_input').attr('class', a);
        }

        //Demo
        layui.use(['form', 'jquery'], function () {
            var form = layui.form();
            $ = layui.jquery;
            form.render();
            //监听提交
            form.on('submit(formDemo)', function (data) {
            });
            $(document).on('click', '.layui-btn-primary', function () {
                $('#icon_input').attr('class', '{{$permission->icon}}');
            })
        });
    </script>
    </body>
@endsection
